﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SXFramWork.Core;
using SXFramWork.Model;
using SXFramWork.Service;

namespace SXFramWork.API.Controllers.Admin
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    public class SysPermissionController : WebController
    {
        private readonly ISysPermissionService _service;
        public SysPermissionController(ISysPermissionService sysPermissionService)
        {
            _service = sysPermissionService;
        }
        /// <summary>
        /// 查询树形
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Power("获得树形")]
        [AllowAnonymous]
        public async Task<IApiResult> GetTree()
        {
            return await _service.GetTree();
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        [Menu("菜单管理")]
        [AllowAnonymous]
        public async Task<IApiResult> List([FromQuery]MenuQueryModel model)
        {
            return await _service.Query(model);
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("添加")]
        [AllowAnonymous]
        public async Task<IApiResult> Add([FromBody]MenuAddModel model)
        {
            return await _service.Add(model);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("删除")]
        [AllowAnonymous]
        public async Task<IApiResult> Delete([FromBody]string id)
        {
            return await _service.Delete(id);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("更新")]
        [AllowAnonymous]
        public async Task<IApiResult> Update([FromBody]MenuUpdateModel model)
        {
            return await _service.Update(model);
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Power("查询")]
        [AllowAnonymous]
        public async Task<IApiResult> Get([FromQuery]string id)
        {
            return await _service.QueryById(id);
        }

        /// <summary>
        /// 排序
        /// </summary>
        /// <param name="parentId"></param>
        /// <param name="id"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IApiResult> Sort([FromQuery]string parentId,string id,int flag)
        {
            return await _service.Sort(parentId,id,flag);
        }

    }
}